﻿/*
    This file is part of News Worm.

    News Worm is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    News Worm is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with News Worm.  If not, see <http://www.gnu.org/licenses/>.
 */

using System;
using System.Windows.Forms;
using System.Collections.Generic;

namespace NewsWorm {
    internal class TreeViewHelper {
        private static Dictionary<string, Dictionary<TreeNode, int>> m_Nodes = new Dictionary<string, Dictionary<TreeNode, int>>();

        internal static TreeNode GetRootTreeNodeByTitle( TreeView view, string title ) {
            foreach ( TreeNode n in view.Nodes ) {
                if ( n.Name.Equals( title ) )
                    return n;
            }

            return null;
        }

        internal static Dictionary<string, Dictionary<TreeNode, int>> ReadNodesHidden {
            get { return m_Nodes; }
        }

        internal static void AddNodeToReadNodes( string key, TreeNode node, int index ) {
            if ( !m_Nodes.ContainsKey( key ) ) {
                Dictionary<TreeNode, int> dict = new Dictionary<TreeNode, int>();
                dict.Add( node, index );
                m_Nodes.Add( key, dict );
            } else {
                Dictionary<TreeNode, int> d = m_Nodes[key];
                if ( !d.ContainsKey( node ) )
                    m_Nodes[key].Add( node, index );
                else {
                    m_Nodes[key].Remove( node );
                    m_Nodes[key].Add( node, index );
                }
            }
        }
    }
}
